package net.lwf.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.lwf.entity.WebUser;
import net.lwf.util.web.WebUtil;
import net.lwf.web.constant.IWebConstant;


public class SessionData {
	
//	public static String getAppHitCounter(HttpServletRequest request) {
//		long apphits = 0;
//		Long obj = (Long) WebUtil.getAttribute(request, IWebConstant.APP_HITS);
//		if(obj != null) {
//			apphits = obj.longValue();
//		}
//		else {
//			apphits = new UserService().getHitCounter();
//			WebUtil.setAttribute(request, IWebConstant.APP_HITS, new Long(apphits));
//		}
//		return String.valueOf(apphits);
//	}
	
	public static String getUserId(HttpServletRequest request) {
		WebUser user = (WebUser) WebUtil.getAttribute(request, IWebConstant.WEB_USER);
		if(user != null) {
			return user.getUser().getUserId();
		}
		return null;
	}
	
	
	public static void invalidateData(HttpServletRequest request) {
		HttpSession session = request.getSession(false);
		if(session != null) {
			session.invalidate();
		}
		request.getSession().invalidate();
	}

}
